<template>
  <v-overlay>
    <div
      class="open-result-dialog"
      :class="{ 'more-line': listData.length > 3 }"
    >
      <div class="card-list-box">
        <div class="card-list-wrapper">
          <div class="card-list">
            <div
              class="card-item justify-space-between"
              v-for="(skin, index) in listData"
              :key="index"
              :style="{
                'background-color': getBackgroundColor(skin),
              }"
            >
              <div>
                <img class="card-image" :src="skin.image_url" alt="" />
                <div class="card-name text-overflow-2">
                  {{ skin.item_name }}
                </div>
              </div>
              <v-spacer></v-spacer>
              <v-btn size="small" variant="outlined" @click="sell(skin)">
                {{ skin.has_sold ? "已出售" : "出售" }}

                <img
                  style="width: 1.3rem; margin: 0 0.3rem"
                  src="/src/static/img/icon/diamonds.png"
                  alt=""
                />
                {{ skin.price }}
              </v-btn>
            </div>
          </div>
        </div>

        <!-- <v-row> -->
        <div class="open-result-action">
          <v-btn flat @click="sellAll">全部出售</v-btn>
          <v-btn flat @click="close">存入背包</v-btn>
        </div>
        <!-- </v-row> -->
      </div>

      <i class="el-icon-close close-icon" @click="close"></i>
    </div>
  </v-overlay>
</template>

<script lang="ts">
import { OpenBoxResult } from "@/types";
import { colorRgb } from "@/utils";
import { defineComponent } from "vue";

export default defineComponent({
  props: {
    listData: {
      type: Array,
      default: () => [],
    },
  },

  methods: {
    close() {
      this.$emit("close");
    },

    sell(data: OpenBoxResult) {
      this.$emit("sell", data);
    },

    sellAll() {
      this.$emit("sell-all");
    },

    getBackgroundColor(data: OpenBoxResult) {
      return colorRgb(data.rarity_color, 0.9);
    },
  },
});
</script>

<style scoped lang="scss">
.open-result-dialog {
  width: 100vw;
  max-width: 90rem;
  height: 30rem;
  display: flex;
  justify-content: center;
  align-items: center;
  color: #fff;
  text-align: center;
  background: rgba(0, 0, 0, 0.2);

  .more-line {
    margin-bottom: 2rem;
  }
}

.card-list-wrapper {
  width: 100%;
  text-align: center;
  overflow-x: auto;
  margin: 0 auto;
}

.card-list {
  display: inline-flex;
  width: max-content;
}

.card-item {
  background: rgba(152, 160, 235, 0.9);
  padding: 1rem 1rem;
  border-radius: 0.3rem;
  display: flex;
  flex-direction: column;
  width: 15rem;
  margin: 0 0.5rem;
  max-width: 160px;
  max-height: 260px;
  flex: none;

  &:last-child {
    margin-right: 0;
  }

  .card-image {
    width: 100%;
    // height: 8rem;
    margin: 1rem auto 0.8rem auto;
    display: block;
  }

  .card-name {
    font-size: 1rem;
    margin: 1rem 0;
    word-break: normal;
    word-wrap: break-word;
    white-space: normal;
  }
}

.text-overflow-2 {
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  overflow: hidden;
}

.open-result-action {
  display: flex;
  justify-content: center;
  margin-top: 1.6rem;
  width: 100%;
  color: #333;

  > * {
    margin: 0 2rem;
  }
}

.close-icon {
  font-size: 30px;
  cursor: pointer;
  position: absolute;
  top: 0;
  right: 0;
  font-weight: bold;
}

.card-list-box {
  width: 90%;

  .card-list-wrapper {
    // height: 23rem;
    overflow-x: auto;
    // white-space: nowrap;
    padding-bottom: 6px;
  }
}

@media screen and (max-width: 900px) {
  .card-list-box {
    width: 80%;

    .card-list {
      height: 16rem;

      .card-item {
        width: 36vw;
        padding: 0.5rem;

        .card-name {
          margin: 0.3rem 0;
        }

        .card-image {
          width: 80%;
          height: auto;
        }
      }
    }
  }

  .close-icon {
    top: 0.5rem;
    right: 0.5rem;
  }
}
</style>
